package com.wt.admin.controller.image;


import com.aizuda.easy.security.domain.Rep;
import com.aizuda.easy.security.util.LocalUtil;
import com.wt.admin.config.aspect.annotation.LogAno;
import com.wt.admin.domain.dto.image.ImageClassificationDTO;
import com.wt.admin.domain.dto.image.ImageItemDTO;
import com.wt.admin.domain.vo.image.ImageClassificationListVO;
import com.wt.admin.domain.vo.image.ImageClassificationVO;
import com.wt.admin.domain.vo.image.ImageFeaturesVO;
import com.wt.admin.domain.vo.image.ImageItemVO;
import com.wt.admin.service.image.ImageProxyService;
import com.wt.admin.util.PageUtil;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.List;

@RestController
@RequestMapping("imageClassification")
public class ImageClassificationController {

    @Resource
    private ImageProxyService imageProxyService;

    @LogAno(name = "添加图像分类")
    @PostMapping("add")
    public Rep<ImageClassificationVO> add(@RequestBody ImageClassificationDTO data){
        return Rep.ok(imageProxyService.getImageClassificationService().add(data));
    }

    @LogAno(name = "图像分类列表")
    @PostMapping("list")
    public Rep<ImageClassificationListVO> list(@RequestBody ImageClassificationDTO data){
        return Rep.ok(imageProxyService.list(data));
    }

    @LogAno(name = "删除图像分类")
    @PostMapping("del")
    public Rep<ImageClassificationVO> del(@RequestBody ImageClassificationDTO data){
        return Rep.ok(imageProxyService.imageClassificationDel(data));
    }

    @LogAno(name = "编辑图像分类")
    @PostMapping("edit")
    public Rep<ImageClassificationVO> edit(@RequestBody ImageClassificationDTO data){
        return Rep.ok(imageProxyService.getImageClassificationService().edit(data));
    }

    @LogAno(name = "查询图片列表")
    @PostMapping("imageList")
    public Rep<PageUtil.PageVO<ImageItemVO>> imageList(@RequestBody PageUtil.PageDTO<ImageItemDTO> data){
        return Rep.ok(imageProxyService.getImageItemService().imageList(data));
    }

    @LogAno(name = "查询分类下的特征")
    @PostMapping("featuresList")
    public Rep<List<ImageFeaturesVO>> featuresList(@RequestBody ImageItemDTO data){
        return Rep.ok(imageProxyService.getImageFeaturesService().featuresList(data));
    }

    @LogAno(name = "编辑图像的配置")
    @PostMapping("editItemFeatures")
    public Rep<ImageItemVO> editItemFeatures(@RequestBody ImageItemDTO data){
        return Rep.ok(imageProxyService.getImageItemService().editItemFeatures(data));
    }

    @LogAno(name = "删除图像")
    @PostMapping("delImageItem")
    public Rep<ImageItemVO> delImageItem(@RequestBody List<String> data){
        return Rep.ok(imageProxyService.getImageItemService().delImageItem(data));
    }

    @LogAno(name = "图片训练")
    @PostMapping("imageTraining")
    public Rep<ImageClassificationDTO> imageTraining(@RequestBody ImageClassificationDTO data){
        imageProxyService.imageTraining(data, LocalUtil.getUser());
        return Rep.ok();
    }

    @PostMapping("/testTraining")
    public Rep<String> testTraining(@RequestParam("file") MultipartFile file,@RequestParam("id") Integer id,@RequestParam("model") String model) throws IOException {
        return Rep.ok(imageProxyService.testTraining(file,id,model));
    }

}
